package com.pineapple.module.core.remove.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.pineapple.module.core.planting.service.PlantingManager;
import com.pineapple.module.core.remove.domain.Remove;
import com.pineapple.module.core.remove.domain.RemoveCriteria;
import com.pineapple.module.core.remove.domain.RemoveSearch;

public class RemoveManager {
	RemoveDAO dao = null;

	public RemoveManager(){
		dao = new RemoveDAO();
	}

	public List<RemoveSearch> search(RemoveCriteria criteria,Connection conn)throws Exception{
		List<RemoveSearch> lstRemove = new ArrayList<RemoveSearch>();
		int totalRacord =dao.count(criteria, conn);
		criteria.setTotalResult(totalRacord);
		if (criteria.getTotalResult() < criteria.getStart()) {
			criteria.setStart(criteria.getStart() - criteria.getLinePerPage());
		}
			if(totalRacord>0){
				lstRemove = dao.search(criteria, conn);
		}
		return lstRemove;
	}

	/*public Map<String,String> pineappleCombo(Connection conn)throws Exception{
		return dao.pineappleCombo(conn);
	}
	public Map<String,String> areaCombo(Connection conn)throws Exception{
		return dao.areaCombo(conn);
	}*/



	public void add(Connection conn,Remove remove)throws Exception{
		 PlantingManager manager = new PlantingManager();
		 manager.updateStatus(conn, remove.getPlantingId(), "0");
		 dao.add(conn, remove);
	}
	public void edit(Connection conn,Remove planting)throws Exception{
		dao.edit(conn, planting);
	}
	public void delete(Connection conn,String plantingIds)throws Exception{
		PlantingManager manager = new PlantingManager();
		String arr[] = plantingIds.split(",");
		for(String id : arr){
			manager.updateStatus(conn,id, "2");
		}
		dao.delete(conn, plantingIds);
	}
	public Remove searchById(Connection conn,int id)throws Exception{
		return dao.searchById(conn, id);
	}
	public Map<String,String> searchComboPlantAndArea(Connection conn)throws Exception{
		return dao.searchComboPlantAndArea(conn);
	}

}
